package com.substation.ui.fragment;

import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.greenentity.Eqpt;
import com.jessewu.library.SuperAdapter;
import com.jessewu.library.view.ViewHolder;
import com.substation.R;
import com.substation.greendao.EqptDao;
import com.substation.ui.utils.RecyclerViewUtils;
import com.substation.utils.GreenDaoManager;
import com.substation.utils.SPUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by admin on 2018/5/28.
 * 工器具
 */

public class EqptFragment extends BaseFragment {
    @BindView(R.id.list)
    RecyclerView list;
    SuperAdapter<Eqpt> adapter;
    List<Eqpt> datas = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_eqpt;
    }

    @Override
    protected void initView() {

        list.setLayoutManager(RecyclerViewUtils.getLinearLayoutManagerForVertical(context));
        list.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
        list.setAdapter(adapter = new SuperAdapter<Eqpt>(R.layout.content_eqpt_fragment) {
            @Override
            public void bindView(ViewHolder viewHolder, Eqpt eqpt, int i) {
                ((TextView) viewHolder.getView(R.id.name)).setText(eqpt.getEqptName());
                ((TextView) viewHolder.getView(R.id.classfy)).setText(eqpt.getEqptClassifyvalue());
                ((TextView) viewHolder.getView(R.id.type)).setText(eqpt.getEqptModelvalue());
                ((TextView) viewHolder.getView(R.id.status)).setText(eqpt.getStatusvalue());
            }
        });
        adapter.setData(datas);
        adapter.setEmptyDataView(R.layout.view_empty);
    }

    @Override
    public void onResume() {
        super.onResume();
        String guid= (String) SPUtils.get(context,"sub_guid","");
        List<Eqpt> eqpts= GreenDaoManager.getInstance().getmDaoSession().getEqptDao().queryBuilder().where(EqptDao.Properties.SubsGuid.eq(guid)).list();
        datas.addAll(eqpts);
        adapter.notifyDataSetChanged();
    }
}
